package zjut.cocouml.command;

import org.eclipse.gef.commands.Command;

import zjut.cocouml.model.BClass;
import zjut.cocouml.model.BMethod;
import zjut.cocouml.model.Compartment;

public class BMethodCreateCommand extends Command {
	
	private Compartment parent;
	private BMethod model;

	public void setParent(Object parent) {
		if (parent instanceof Compartment)
			this.parent = (Compartment)parent;
	}

	public void setModel(Object model) {
		if (model instanceof BMethod)
			this.model = (BMethod)model;
	}
	
	public boolean canExecute() {
		if (model == null || parent == null) 
			return false;
		return true;
	}
	public void execute() {
		parent.addChild(model);
	}
	public boolean canUndo() {
		if (parent == null || model == null)
			return false;
		return parent.contains(model);
	}
	public void undo() {
		parent.removeChild(model);
	}
	
}
